package answer_factory;

import java.util.LinkedList;
import java.util.List;

import answers.IAnswer;
import answers.MultipleChoiceAnswer;

public class MulitpleChoiceAnswerFactory implements IAnswerFactory
{		
	@Override
	public IAnswer createAnswer(String encoding)
	{
		String [] tokens = encoding.split("\\s");
		if(tokens.length != 3)
		{
			return null;
		}
		
		String answerSet = tokens[2];
		if(!answerSet.startsWith("(") || !answerSet.endsWith(")"))
		{
			return null;
		}
		answerSet = answerSet.substring(1);
		answerSet = answerSet.substring(0, answerSet.length() - 1);
		
		String [] choices = answerSet.split(",");
		List<String> choiceList = new LinkedList<String>();
		for(int i = 0; i < choices.length; ++i)
		{
			choiceList.add(choices[i]);
		}
		
		return new MultipleChoiceAnswer(choiceList);
	}
}
